<?php
require_once('../config/auth.php');
require_once('service.cl.php');
$__CURRENT_PAGE__ = 'service';
$__TITLE__ = "Formulaire d'ajouter un service";
$service = new Service();
$departements = $service->getDepartement()->getAllDepartements();
$message = '';
if(count($_POST) > 0 ) {
  $serviceData = $service->save($_POST);
    if(!$service->hasError()) {
        $message = "<div class='alert alert-success'>Service sauvegardés avec succès</div>";
    }
}
elseif(!empty($_GET['id'])) {
    $service->loadServiceById($_GET['id']);
}
require_once(dirname(__FILE__).'/../config/head.php');
?>
<body>
<?php require_once(dirname(__FILE__).'/../config/menu.php'); ?>
<div class="container">
 <h1>Ajouter un service</h1>
 <?php echo $message ?>
 <form method="post">
  <input type="hidden" name="id" value="<?php echo $service->getId() ?>" />
  <br>
  <div class="row">
    <div class="span4">
      <select name="departement_id">
          <option value="">Selectionner un departement</option>
          <?php foreach($departements as $depart): ?>
          <option  <?php echo ($service->getDepartementId() == $depart->id)  ? 'selected="selected"' : '' ?>
          value="<?php echo $depart->id?>"><?php echo $depart->name ?></option>   
          <?php endforeach ?>
      </select>
      <?php echo $service->getError('departement_id') ?>
    </div>
 </div>

 <div class="row">
    <div class="span4">
        <label>Nom:</label>
        <input type="text" name="name" size="50" maxlength="100" value="<?php echo $service->getName() ?>">
        <?php echo $service->getError('name') ?>
    </div> 
    <div class="span4">   
       <label>Abreviation:</label>
       <input type="text" name="abreviation" size="50" maxlength="50" value="<?php echo $service->getAbreviation() ?>">
       <?php echo $service->getError('abreviation') ?>
    </div>
  </div> 
  <div class="row">
     <div class="span2">
         <input type="reset" value="Annuler" class="btn btn-large btn-block">
     </div>
     <div class="span2 offset3">
         <input type="submit" value="Valider" class="btn btn-success btn-large btn-block">
     </div>
 </div>
 </form>
</div> 
</body>